package com.wideplay.warp.remoting;

import java.lang.annotation.Annotation;

/**
 * Created by IntelliJ IDEA.
 * User: dprasanna
 * Date: 1/10/2007
 * Time: 16:11:17
 * <p/>
 *
 * Builds a Remoting scope.
 * TODO find some way to validate if the scope has been fully built.
 *
 * @author dprasanna
 * @since 1.0
 */
class RemoteScopeBuilderImpl implements ProtocolBindingBuilder, HostBindingBuilder {
    private String host = "localhost";
    private int port;
    private Transports protocol;

    private final AbstractRemotingModule remotingModule;
    private final Class<? extends Annotation> annotation;

    public RemoteScopeBuilderImpl(AbstractRemotingModule remotingModule, Class<? extends Annotation> annotation) {
        this.remotingModule = remotingModule;
        this.annotation = annotation;
    }

    public HostBindingBuilder via(Transports protocol) {
        this.protocol = protocol;
        
        return this;
    }

    public void at(int port) {
        this.port = port;

        remotingModule.doScopeBinding(build());
    }

    public void at(String host, int port) {
        this.host = host;
        this.port = port;

        remotingModule.doScopeBinding(build());
    }

    RemoteScopeDescriptor build() {
        return new RemoteScopeDescriptor(protocol, annotation, host, port);
    }
}
